package com.example.springaop.proxy;

import net.sf.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;

public class Main {

    public static void main(String[] args) {
//        HouseSubject houseSubject = new RealHouseSubject();
//        //JDK实现动态代理
//        //创建一个代理类
//        //通过被代理类,被代理类实现的接口,方法调用处理器来创建
//        HouseSubject proxy = (HouseSubject) Proxy.newProxyInstance(
//                houseSubject.getClass().getClassLoader(),
//                new Class[]{HouseSubject.class},
//                new JDKInvocationHandler(houseSubject)
//        );
//        proxy.rent();

        HouseSubject target = new RealHouseSubject();
        HouseSubject proxy2 = (HouseSubject) Enhancer.create(target.getClass(),new CGLibIntercepter(target));
        proxy2.rent();
    }
}
